﻿using System;
using Aeon.Emulator.Memory;

namespace Aeon.Emulator
{
    /// <summary>
    /// Contains information about expanded memory usage.
    /// </summary>
    public sealed class ExpandedMemoryInfo
    {
        #region Constructors
        /// <summary>
        /// Initializes a new instance of the ExpandedMemoryInfo class.
        /// </summary>
        /// <param name="allocatedPages">Number of pages currently allocated.</param>
        internal ExpandedMemoryInfo(int allocatedPages)
        {
            this.allocatedPages = allocatedPages;
        }
        #endregion

        #region Public Properties
        /// <summary>
        /// Gets the number of pages allocated.
        /// </summary>
        public int PagesAllocated
        {
            get { return allocatedPages; }
        }
        /// <summary>
        /// Gets the number of bytes allocated.
        /// </summary>
        public int BytesAllocated
        {
            get { return this.PagesAllocated * ExpandedMemoryManager.PageSize; }
        }
        /// <summary>
        /// Gets the number of free pages.
        /// </summary>
        public int PagesFree
        {
            get { return Math.Max(TotalPages - this.PagesAllocated, 0); }
        }
        /// <summary>
        /// Gets the number of free bytes.
        /// </summary>
        public int BytesFree
        {
            get { return Math.Max(TotalBytes - this.BytesAllocated, 0); }
        }
        #endregion

        #region Private Fields
        private readonly int allocatedPages;
        #endregion

        #region Public Constants
        /// <summary>
        /// Size of expanded memory in pages.
        /// </summary>
        public const int TotalPages = ExpandedMemoryManager.MaximumLogicalPages;
        /// <summary>
        /// Size of expanded memory in bytes.
        /// </summary>
        public const int TotalBytes = TotalPages * ExpandedMemoryManager.PageSize;
        #endregion
    }
}
